package com.lz.abstractlist;

import com.iflytek.xiri2.hal.HALUtil;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings.Secure;

/**
 * 实现类
 * 
 * @author admin
 * 
 */
public class HardwareIML implements HardwareINF {
	// 帮助类
	private HALUtil halUtil;

	public HardwareIML(Context context) {
		halUtil = new HALUtil(context, 15);
	}

	@Override
	public String getMode() {
		return "TV";
	}

	@Override
	public String getDeviceId(Context context) {
		return getAndroidId(context);
	}

	@Override
	public int getMaxVolume(Context context) {
		return 60;
	}

	@Override
	public int getMinVolume(Context context) {
		return 0;
	}

	@Override
	public int getVoluemStep() {
		return 7;
	}

	@Override
	public int getMaxBrightness(Context context) {
		return 0;
	}

	@Override
	public int getMinBrightness(Context context) {
		return 0;
	}

	@Override
	public int getBrightnessmStep() {
		return 0;
	}

	@Override
	public String[] getDefaulttvapplst() {
		return null;
	}

	@Override
	public boolean setMuteACTION(Context context, boolean mute) {
		if (mute) {
			halUtil.__mute(context);
		} else {
			halUtil.__unmute(context);
		}
		return true;
	}

	@Override
	public int getCurVolume(Context context) {
		return halUtil.getCurVolume(context);
	}

	@Override
	public void setVolume(Context context, int volume) {
		halUtil.setVolume(volume);
	}

	@Override
	public boolean getCurMuteState(Context context) {
		return false;
	}

	@Override
	public void setMuteState(boolean state, Context context) {

	}

	@Override
	public boolean navigateACTION(Context context, String url) {
		halUtil.search_internet(url);
		return true;
	}

	@Override
	public boolean soundSettingACTION(Context context) {
		try {
			Intent intent = new Intent("mipt.qiyi.settings.action.SOUND");
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			context.startActivity(intent);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public boolean networkSettingACTION(Context context) {
		try {
			Intent intent = new Intent("mipt.qiyi.settings.action.NETWORK");
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			context.startActivity(intent);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public boolean systemSettingACTION(Context context) {
		Intent intent_settings = new Intent();
		intent_settings.setComponent(new ComponentName("com.android.settings",
				"com.android.settings.Settings"));
		intent_settings.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent_settings);
		return true;
	}

	@Override
	public boolean imageSettingACTION(Context context) {
		try {
			Intent intent = new Intent("mipt.qiyi.settings.action.BACKGROUND");
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			context.startActivity(intent);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public boolean sendKeyACTION(Context context, int keyCode) {
		// 发送虚拟按键
		return true;
	}

	@Override
	public boolean powerOffACTION(Context context) {
		// 关机
		return true;
	}

	@Override
	public boolean setSignalSourceACTION(Context context, String signalsource) {
		return false;
	}

	@Override
	public String getSignalSourceListACTION() {
		return null;
	}

	@Override
	public boolean increaseBrightnessACTION(Context context) {
		return false;
	}

	@Override
	public boolean decreaseBrightnessACTION(Context context) {
		return false;
	}

	@Override
	public int getBrightnessACTION(Context context) {
		return 0;
	}

	@Override
	public boolean setBrightnessACTION(Context context, int brightness) {
		return false;
	}

	/**
	 * 获取设备Id
	 * 
	 * @return
	 */
	public String getAndroidId(Context context) {
		String id = null;
		try {
			id = Secure.getString(context.getContentResolver(),
					Secure.ANDROID_ID);
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return id;
	}
}
